using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVLORT
    {
        public DataRow Convert2VLORT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVLORT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VLOMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VLOLKZ"] = " ".PadRight(3 ); 
         dwReturn["VLOPLZ"] = " ".PadRight(12 ); 
         dwReturn["VLOORT"] = " ".PadRight(40 ); 
         dwReturn["VLOBZ"] = " ".PadRight(2 ); 
         dwReturn["VLOORTBEZ"] = " ".PadRight(40 ); 
         dwReturn["VLOBZBEZ"] = " ".PadRight(25 ); 
         dwReturn["VLOCOUNTY"] = " ".PadRight(4 ); 
         dwReturn["VLOCITY"] = " ".PadRight(4 ); 
         dwReturn["VLOGTBO"] = " ".PadRight(6 ); 
         dwReturn["VLOORTO"] = " ".PadRight(40 ); 
         dwReturn["VLOORTKL1"] = " ".PadRight(2 ); 
         dwReturn["VLOORTKL2"] = " ".PadRight(2 ); 
         dwReturn["VLOORTKL3"] = " ".PadRight(2 ); 
         dwReturn["VLOORTKL4"] = " ".PadRight(2 ); 
         dwReturn["VLOORTKL5"] = " ".PadRight(2 ); 
         dwReturn["VLOGTBS"] = " ".PadRight(6 ); 
         dwReturn["VLOORTS"] = " ".PadRight(40 ); 
         dwReturn["VLOLOEF1"] = " ".PadRight(2 ); 
         dwReturn["VLOSKMEF1"] = " ".PadRight(4 ); 
         dwReturn["VLOBKMEF1"] = " ".PadRight(4 ); 
         dwReturn["VLOLOEF2"] = " ".PadRight(2 ); 
         dwReturn["VLOSKMEF2"] = " ".PadRight(4 ); 
         dwReturn["VLOBKMEF2"] = " ".PadRight(4 ); 
         dwReturn["VLOLOEF3"] = " ".PadRight(2 ); 
         dwReturn["VLOSKMEF3"] = " ".PadRight(4 ); 
         dwReturn["VLOBKMEF3"] = " ".PadRight(4 ); 
         dwReturn["VLOPLZF"] = " ".PadRight(12 ); 
         dwReturn["VLOORTF"] = " ".PadRight(40 ); 
         dwReturn["VLOBZF"] = " ".PadRight(2 ); 
         dwReturn["VLOPLZE"] = " ".PadRight(12 ); 
         dwReturn["VLOORTE"] = " ".PadRight(40 ); 
         dwReturn["VLOBZE"] = " ".PadRight(2 ); 
         dwReturn["VLOAENZL"] = " ".PadRight(0 ); 
         dwReturn["VLOFILLER"] = " ".PadRight(26 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVLORT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVLORT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVLORT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVLORT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVLORT(dwLocal, ITXDBVERSION);
            }
            UpdateVLORT(dwLocal);
        }
        public void InsertVLORT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VLORT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVLORT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VLORT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VLORT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VLORT";
            Return = Result;
            return Return;
        }
        public void DeleteVLORT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VLORT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVLORT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VLORT SET "
                    +"VLOMANDANT= :VLOMANDANT,"
                    +"VLOLKZ= :VLOLKZ,"
                    +"VLOPLZ= :VLOPLZ,"
                    +"VLOORT= :VLOORT,"
                    +"VLOBZ= :VLOBZ,"
                    +"VLOORTBEZ= :VLOORTBEZ,"
                    +"VLOBZBEZ= :VLOBZBEZ,"
                    +"VLOCOUNTY= :VLOCOUNTY,"
                    +"VLOCITY= :VLOCITY,"
                    +"VLOGTBO= :VLOGTBO,"
                    +"VLOORTO= :VLOORTO,"
                    +"VLOORTKL1= :VLOORTKL1,"
                    +"VLOORTKL2= :VLOORTKL2,"
                    +"VLOORTKL3= :VLOORTKL3,"
                    +"VLOORTKL4= :VLOORTKL4,"
                    +"VLOORTKL5= :VLOORTKL5,"
                    +"VLOGTBS= :VLOGTBS,"
                    +"VLOORTS= :VLOORTS,"
                    +"VLOLOEF1= :VLOLOEF1,"
                    +"VLOSKMEF1= :VLOSKMEF1,"
                    +"VLOBKMEF1= :VLOBKMEF1,"
                    +"VLOLOEF2= :VLOLOEF2,"
                    +"VLOSKMEF2= :VLOSKMEF2,"
                    +"VLOBKMEF2= :VLOBKMEF2,"
                    +"VLOLOEF3= :VLOLOEF3,"
                    +"VLOSKMEF3= :VLOSKMEF3,"
                    +"VLOBKMEF3= :VLOBKMEF3,"
                    +"VLOPLZF= :VLOPLZF,"
                    +"VLOORTF= :VLOORTF,"
                    +"VLOBZF= :VLOBZF,"
                    +"VLOPLZE= :VLOPLZE,"
                    +"VLOORTE= :VLOORTE,"
                    +"VLOBZE= :VLOBZE,"
                    +"VLOAENZL= :VLOAENZL,"
                    +"VLOFILLER= :VLOFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VLOMANDANT", OracleType.NVarChar).Value = dwData["VLOMANDANT"].ToString(); 
          or1.Parameters.Add("VLOLKZ", OracleType.NVarChar).Value = dwData["VLOLKZ"].ToString(); 
          or1.Parameters.Add("VLOPLZ", OracleType.NVarChar).Value = dwData["VLOPLZ"].ToString(); 
          or1.Parameters.Add("VLOORT", OracleType.NVarChar).Value = dwData["VLOORT"].ToString(); 
          or1.Parameters.Add("VLOBZ", OracleType.NVarChar).Value = dwData["VLOBZ"].ToString(); 
          or1.Parameters.Add("VLOORTBEZ", OracleType.NVarChar).Value = dwData["VLOORTBEZ"].ToString(); 
          or1.Parameters.Add("VLOBZBEZ", OracleType.NVarChar).Value = dwData["VLOBZBEZ"].ToString(); 
          or1.Parameters.Add("VLOCOUNTY", OracleType.NVarChar).Value = dwData["VLOCOUNTY"].ToString(); 
          or1.Parameters.Add("VLOCITY", OracleType.NVarChar).Value = dwData["VLOCITY"].ToString(); 
          or1.Parameters.Add("VLOGTBO", OracleType.NVarChar).Value = dwData["VLOGTBO"].ToString(); 
          or1.Parameters.Add("VLOORTO", OracleType.NVarChar).Value = dwData["VLOORTO"].ToString(); 
          or1.Parameters.Add("VLOORTKL1", OracleType.NVarChar).Value = dwData["VLOORTKL1"].ToString(); 
          or1.Parameters.Add("VLOORTKL2", OracleType.NVarChar).Value = dwData["VLOORTKL2"].ToString(); 
          or1.Parameters.Add("VLOORTKL3", OracleType.NVarChar).Value = dwData["VLOORTKL3"].ToString(); 
          or1.Parameters.Add("VLOORTKL4", OracleType.NVarChar).Value = dwData["VLOORTKL4"].ToString(); 
          or1.Parameters.Add("VLOORTKL5", OracleType.NVarChar).Value = dwData["VLOORTKL5"].ToString(); 
          or1.Parameters.Add("VLOGTBS", OracleType.NVarChar).Value = dwData["VLOGTBS"].ToString(); 
          or1.Parameters.Add("VLOORTS", OracleType.NVarChar).Value = dwData["VLOORTS"].ToString(); 
          or1.Parameters.Add("VLOLOEF1", OracleType.NVarChar).Value = dwData["VLOLOEF1"].ToString(); 
          or1.Parameters.Add("VLOSKMEF1", OracleType.NVarChar).Value = dwData["VLOSKMEF1"].ToString(); 
          or1.Parameters.Add("VLOBKMEF1", OracleType.NVarChar).Value = dwData["VLOBKMEF1"].ToString(); 
          or1.Parameters.Add("VLOLOEF2", OracleType.NVarChar).Value = dwData["VLOLOEF2"].ToString(); 
          or1.Parameters.Add("VLOSKMEF2", OracleType.NVarChar).Value = dwData["VLOSKMEF2"].ToString(); 
          or1.Parameters.Add("VLOBKMEF2", OracleType.NVarChar).Value = dwData["VLOBKMEF2"].ToString(); 
          or1.Parameters.Add("VLOLOEF3", OracleType.NVarChar).Value = dwData["VLOLOEF3"].ToString(); 
          or1.Parameters.Add("VLOSKMEF3", OracleType.NVarChar).Value = dwData["VLOSKMEF3"].ToString(); 
          or1.Parameters.Add("VLOBKMEF3", OracleType.NVarChar).Value = dwData["VLOBKMEF3"].ToString(); 
          or1.Parameters.Add("VLOPLZF", OracleType.NVarChar).Value = dwData["VLOPLZF"].ToString(); 
          or1.Parameters.Add("VLOORTF", OracleType.NVarChar).Value = dwData["VLOORTF"].ToString(); 
          or1.Parameters.Add("VLOBZF", OracleType.NVarChar).Value = dwData["VLOBZF"].ToString(); 
          or1.Parameters.Add("VLOPLZE", OracleType.NVarChar).Value = dwData["VLOPLZE"].ToString(); 
          or1.Parameters.Add("VLOORTE", OracleType.NVarChar).Value = dwData["VLOORTE"].ToString(); 
          or1.Parameters.Add("VLOBZE", OracleType.NVarChar).Value = dwData["VLOBZE"].ToString(); 
          or1.Parameters.Add("VLOAENZL", OracleType.NVarChar).Value = dwData["VLOAENZL"].ToString(); 
          or1.Parameters.Add("VLOFILLER", OracleType.NVarChar).Value = dwData["VLOFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
